<?php
class PapiWS_Model_BackgroundVO extends PapiWS_Model_GraphicalObjectVO
{
	const BACKGROUND_IMAGE  = 'background_image';
	const BACKGROUND_FILL   = 'background_fill';
	
	public $id;
	public $nid;
	public $type ;
	public $color = 0;
	public $imageUrl;
	public $fullResUrl;
	public $thumbnailUrl;

    public function __construct( $data = null )
    {
    	$drupalUrl = Zend_Registry::get('config')->drupal->url;
    	$bgImageCacheUrl = Zend_Registry::get('config')->drupal->bgImageCache->url;
        $this->nid = $data['nid'];

		$this->type = self::BACKGROUND_IMAGE;

        if( isset($data['title']) ) {
            $this->name = $data['title'];
        }

    	if( isset($data['field_png'][0]['filepath']) ) {
			$this->fullResUrl = $drupalUrl . $data['field_png'][0]['filepath'];
			$this->imageUrl   = $bgImageCacheUrl . $data['field_png'][0]['filepath'];
			list($this->width, $this->height) = @getimagesize( $this->imageUrl );
		}
		
    	if( isset($data['field_png_thumb'][0]['filepath']) ) {
			$this->thumbnailUrl = $drupalUrl . $data['field_png_thumb'][0]['filepath'];
		}
		
		
		if( isset($data['field_width_mm'][0]['value'])) {
			$this->width = $data['field_width_mm'][0]['value'];
		}
		
		if( isset($data['field_height_mm'][0]['value'])) {
			$this->height = $data['field_height_mm'][0]['value'];
		}
		
		$this->repeatX = false;
		$this->repeatY = false;
		
		if( isset($data['images'])) {
			$this->images = $data['images'];
		}
    }
}
